<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
Refresh = function(){
	//jq的自动完成
	$(".ajax_product").autocomplete("<?=url('Purchase::Loss/ProductInfoAjax')?>").result(function(event, data, formatted){
		if (data[0])
		{
			var container = $(this).parent().parent();
			container.find("input.product_number").val(data['number']);
			container.find("input[name^='product_id']").val(data['id']);
		}
	});
};
$(function(){
	//保存采购单
	$("#add_save").click(function(){
		var can_save = 1;
		//检查添加产品
		$("#loss_list").find("input[name='product_id']").each(function(){
			if (!$(this).val())
			{
				can_save=0;
				alert("请检查每个产品编号");
				return false;
			}
		});
		$("#loss_list").find("input[name='price']").each(function(){
			if (!$(this).val())
			{
				can_save=0;
				alert("请检查每个产品单价");
				return false;
			}
		});
		$("#loss_list").find("input[name='quantity']").each(function(){
			if (!$(this).val())
			{
				can_save=0;
				alert("请检查每个产品数量");
				return false;
			}
		});
		if (can_save)
		{
			$("form").submit();
		}
	});
	Refresh();
});
</script>
<h2>修改采购损耗</h2>
<form action="<?=url('Purchase::Loss/LossEditSave')?>" method="post" id="loss_list">
<input type="hidden" name="purchase_loss_id" value="<?=$purchase_loss['id']?>" />
<table class="form_table">
	<tr>
		<th>创建人员</th>
		<td><?=$purchase_loss['create_user_name']?></td>
	</tr>
	<tr>
		<th>产品编号</th>
		<td><input type="text" size="8" disabled="disabled" class="product_number" value="<?=$purchase_loss['number']?>" /><input type="text" size="50" name="product_number" class="ajax_product" value="<?=$purchase_loss['number'] . ' ' . $purchase_loss['name']?>" /><input type="hidden" name="product_id" value="<?=$purchase_loss['product_basic_id']?>" /></td>
	</tr>
	<tr>
		<th>单价</th>
		<td><input type="text" size="8" name="price" value="<?=$purchase_loss['price']?>" /></td>
	</tr>
	<tr>
		<th>数量</th>
		<td><input type="text" size="8" name="quantity" value="<?=$purchase_loss['quantity']?>" /></td>
	</tr>
	<tr>
		<th>损耗原因</th>
		<td><textarea rows="2" cols="30" name="reason" ><?=$purchase_loss['reason']?></textarea></td>
	</tr>
	<tr>
		<th></th>
		<td><input type="button" class="button" id="add_save" value="修改"/></td>
	</tr>
</table>
</form>
<?php $this->_endblock();?>